class _Promise {
    static PENGIND = 'pending';
    static FULFILLED = 'fulfilled';
    static REJECTED = 'rejected';

    constructor(executor) {
        this.value = ''
        this.status = _Promise.PENGIND // 初始化设置状态为中间态
        this.callback = []

        executor(this.resolve.bind(this), this.reject.bind(this))

    }

    resolve(value) {
        if (this.status === _Promise.PENGIND) { }
        this.status = _Promise.FULFILLED
        this.value = value
    }
    reject(reason) {
        if (this.status === _Promise.PENGIND) {
            this.status = _Promise.REJECTED
            this.value = reason
        }
    }
    then(onFulfilled, onRejected) {
        if (typeof onFulfilled !== 'function') {
            onFulfilled = () => { }
        }

        if (typeof onRejected !== 'function') {
            onRejected = () => { }
        }

        return _Promise((resolve, reject) => {
            switch (this.status) {
                case _Promise.FULFILLED:
                    setTimeout(() => {
                        try {
                            onFulfilled(this.value)
                        } catch (e) {
                            onRejected(e)
                        }
                    })
                    break;
                case _Promise.REJECTED:
                    setTimeout(() => {
                        try {
                            onRejected(this.value)
                        } catch (e) {
                            onRejected(e)
                        }
                    });
                case _Promise.REJECTED:

                default:
                    break;
            }

        })
    }
}


// const process = require('process')
// const fs = require('fs');
// const path = require('path');
// const files = fs.readFileSync(path.join(__dirname))
// console.log(files);

// import * as fs from 'fs/promises';
const fs = require('fs/promises');
const path = require('path');

fs.readFile(path.join(__dirname, './手写promise.js'), (err, res) => {
    console.log(err, res);
    console.log('%d hello', 'world');
})

var arr = [
    [1, 2, 2],
    [3, 4, 5, 5],
    [6, 7, 8, 9,
        [11, 12,
            [12, 13, [14]]
        ]
    ],
    10
];

/**
 * 1. 铺平
 * 2. 去重
 * 3. 排序
 */
let arr1 = [...new Set(arr.flat(Infinity))].sort((a, b) => a - b).filter((r, v) => r !== v)
console.log(arr1);